﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using EGym.BL;
using EGym.BL.ControleSessao;
using EGym.BL.Forms;
using EGym.Data;
namespace EGym.Controllers
{
    public class SegurancaController : Controller
    {
        //
        // GET: /Seguranca/Login
        [HttpPost]
        public ActionResult Login(FormCollection form)
        {
            SessaoGestor sessaoGestor = new SessaoGestor(new DBDataContext());
            Sessao sessao = sessaoGestor.RevisaTicketSessao(SessionManager.CachedGuid);
            if (sessaoGestor.LogIn(sessao, form["userName"], form["password"]))
                return RedirectToAction("Index","Home");

            return RedirectToAction("LoginInvalido", "Home");
        }
        //
        // GET: /Seguranca/Logoff
        public ActionResult Logoff()
        {
            SessionManager.Logoff();
            SessaoGestor sessaoGestor = new SessaoGestor(new DBDataContext());
            Sessao sessao = sessaoGestor.RevisaTicketSessao(SessionManager.CachedGuid);
            return RedirectToAction("Index", "Home");
        }

    }
}
